Skip to content

feat: simpler component configuration #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 19, 2025
Merged

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented May 17, 2025

To simplify the configuration used for component plug-ins, CMS_COMPONENT_PLUGINS now accepts entries with a plug-in name in addition to a dotted path. It will look up the plug-in on the plug-in pool.

Tests are coming up.

Summary by Sourcery

Simplify component plugin configuration to accept plugin names or dotted paths, introduce resolution logic, prevent duplicate registrations, and update tests and documentation accordingly.

New Features:

  • Allow CMS_COMPONENT_PLUGINS entries to be specified as plugin names in addition to dotted paths.

Enhancements:

  • Add get_plugin_class helper to resolve plugin classes from names or import paths.
  • Prevent duplicate slot plugin registrations by checking existing plugin names in the pool.
  • Standardize dynamically generated plugin class module to improve consistency.

Documentation:

  • Update front-end component usage documentation to reflect the simplified plugin configuration API.

Tests:

  • Add tests to verify AutoHero plugin registration and name-based plugin resolution in the plugin pools.

Copy link
Contributor

sourcery-ai bot commented May 17, 2025

Reviewer's Guide

This PR refactors component plugin configuration by introducing a helper to resolve plugins by dotted path or pool name and moving allowed_plugin_types generation into setup; it enhances slot plugin registration with conflict checks, standardizes module paths for dynamically created plugins, and updates settings and tests to support name-based plugin lookup.

File-Level Changes

Change Details Files
Simplified component plugin configuration
  • Removed module-level allowed_plugin_types
  • Introduced get_plugin_class to resolve plugins by dotted path or pool lookup
  • Refactored setup() to build allowed_plugin_types dynamically using get_plugin_class
djangocms_frontend/plugin_tag.py
Enhanced slot plugin registration
  • Added duplicate-name check before registering slot plugins
  • Wrapped registration in conditional to avoid re-registering existing plugins
djangocms_frontend/cms_plugins.py
Standardized dynamic plugin module path
  • Overrode module in plugin_factory to a fixed module
  • Ensured generated plugins appear under djangocms_frontend.cms_plugins
djangocms_frontend/component_base.py
Extended settings and tests for name-based lookup
  • Added plain plugin names (e.g. TextPlugin, AutoHeroPlugin) to CMS_COMPONENT_PLUGINS
  • Added tests to verify plugin registration by name in plugin pools
tests/test_settings.py
tests/test_plugin_tag.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codecov bot commented May 17, 2025

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.65%. Comparing base (434ec8a) to head (a65a860).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
djangocms_frontend/plugin_tag.py 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #279      +/-   ##
==========================================
- Coverage   88.68%   88.65%   -0.03%     
==========================================
  Files         124      124              
  Lines        3366     3376      +10     
  Branches      283      287       +4     
==========================================
+ Hits         2985     2993       +8     
- Misses        264      265       +1     
- Partials      117      118       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fsbraun fsbraun marked this pull request as draft May 17, 2025 05:59
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @fsbraun - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Guard against empty allowed_plugin_types to avoid TypeError (link)
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 5 other issues
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -11,7 +12,7 @@ def update_plugin_pool():
from .component_pool import components

# Loop through the values in the components' registry
for _, plugin, slot_plugins in components._registry.values():
for key, (_, plugin, slot_plugins) in components._registry.items():
if plugin.__name__ not in plugin_pool.plugins:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:

fsbraun and others added 4 commits May 18, 2025 18:54
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@fsbraun fsbraun marked this pull request as ready for review May 19, 2025 11:05
@fsbraun fsbraun merged commit e0c0acd into master May 19, 2025
32 of 34 checks passed
@fsbraun fsbraun deleted the feat/simpler-component-config branch May 19, 2025 11:06
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @fsbraun - I've reviewed your changes - here's some feedback:

  • In update_plugin_pool, you have a redundant nested for slot_plugin in slot_plugins loop—remove the inner loop to avoid double iteration.
  • Overriding the plugin class’s module to a constant string may break introspection or pickling—consider keeping the original module or documenting this change.
  • get_plugin_class silently fails if plugin_pool.get_plugin can’t find a name—consider raising a clear exception or logging a descriptive error.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

plugin_pool.register_plugin(slot_plugin)
# Register slot plugins, checking for name conflicts
for slot_plugin in slot_plugins:
if slot_plugin.__name__ not in plugin_pool.plugins:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Conflict check using class name may not align with plugin_pool API

Confirm which key plugin_pool.plugins uses (e.g., plugin_name) and use that instead of name to detect conflicts accurately.

@@ -174,7 +174,7 @@ def plugin_factory(cls) -> type:
if hasattr(cls, "get_render_template")
else {}
),
"__module__": cls.__module__,
"__module__": "djangocms_frontend.cms_plugins",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Hardcoding module may affect debugging and serialization

Overriding module can break stack traces, pickling, and introspection. Either keep the original module or use qualname to group classes.

Suggested change
"__module__": "djangocms_frontend.cms_plugins",
"__module__": cls.__module__,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant